// store/index.js (Vuex store setup)
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const IS_PRO = true;

export const store = new Vuex.Store({
  state: {
    baseUrl: IS_PRO ? "https://api.chzjzs.top/" : "https://api.zbqjc.com/",
    user_id: uni.getStorageSync('user_id'),
    shop_id: uni.getStorageSync('shop_id'),
    adult: uni.getStorageSync('isAdult'), // 是否成年 0 T 1F
    user_money: 0, // 用户余额
    access_token: uni.getStorageSync('access_token'), // 令牌
    refresh_token: uni.getStorageSync('refresh_token'), // 长期令牌用来刷新
    user_imgs: null,
    hasLogin: false, // 是否登录
    sfz_id: 0,
    sfz_name: null,
    UserConfig: [], // 用户更多参数
    Betrecord: [], // 我的 投注记录
    onHide_boole: false, // 是否后台进入（启动app不会触发全局onHide方法，用于用户长期挂在后台token过期后用户进入无法跳转值登录的问题）
    submitData: [], // 数字类彩票'不用了'
    submitNewData: [], // 数字类彩票投注单
    userinfo: [],
    matchInfoList: [], // 竞彩足球
    BettingContent: [], // 投注内容
    styleData: { data: [] }, // 体彩样式变更
    allOrderData: [],
    userAllData: [], // 用户所有的信息
    gameAstrict: [], // 首页玩法用户点击限制
    allGameAstrict: [], // 首页所有玩法限制
    skipDetails: [], // 跟单/合买大厅跳转详情
    shop_info: [], // 用户上级店铺信息
    user_chatList: [], // 聊天室聊天记录
    chatPageExecute_user: '', // 聊天页面数据执行（用于监听后同步数据）
  },
  
  mutations: {
    // Direct mutation of state (like setters)
    setMoney(state, { type, value }) {
      if (type === 'Dele') {
        state.user_money = Number(state.user_money) - Number(value);
      }
    },

    // Other mutations can be added as needed
    setUserData(state, { userId, shopId, accessToken }) {
      state.user_id = userId;
      state.shop_id = shopId;
      state.access_token = accessToken;
    },
  },

  actions: {
    // Actions that may perform async operations
    setMoney({ commit }, payload) {
      commit('setMoney', payload);
    },

    // Add more actions as needed
    fetchUserData({ commit }) {
      // Simulating async fetching user data, for example:
      const userData = { userId: '123', shopId: '456', accessToken: 'abc' };
      commit('setUserData', userData);
    },
  },

  getters: {
    getUserMoney: state => state.user_money,
    isLoggedIn: state => state.hasLogin,
    getUserInfo: state => state.userinfo,
  },
});
